package org.bit.lesson09;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo_905 {
    public static void main(String[] args) throws InterruptedException {
        // 创建系统自带的线程池
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(3, 5, 1,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(5), new ThreadPoolExecutor.CallerRunsPolicy());

        // 循环向线程池中提交任务
        for (int i = 0; i < 1000; i++) {
            int taskId = i + 1;
            threadPool.submit(() -> {
                System.out.println("执行任务：" + taskId + "," + Thread.currentThread().getName());
            });

           TimeUnit.MILLISECONDS.sleep(1);
        }
    }
}
